package com.burpee.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.burpee.ui.Authority;
import com.burpee.ui.Choice;

@Repository(value="choiceDao")
public class ChoiceDaoImpl implements ChoiceDao {
	
	SqlSessionTemplate sqlSessionTemplate;

	@Autowired
	public void setSqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
	}

	public List<Choice> list() {
		
		List<Choice> list=null;

		try {
			list = sqlSessionTemplate.selectList("choicelist");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return list;
	}

	public Choice view(Choice choice) {
		
		Choice choiceview=new Choice();

		try {
			choiceview = sqlSessionTemplate.selectOne("chiceview", choice);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return choiceview;
	}

	public int add(Choice choice) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.insert("choiceadd",choice);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int modify(Choice choice) {
		
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("choicemodify",choice);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int remove(Choice choice) {
		
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("chiceremove",choice);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

}
